<?php if (!defined('THINK_PATH')) exit();?>﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户管理</title>
	<link rel="stylesheet" href="/Public/easyweb/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/Public/easyweb/assets/module/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        /* 左树 */
        #organizationTreeBar {
            padding: 10px 15px;
            border: 1px solid #e6e6e6;
            background-color: #f2f2f2;
        }

        #organizationTree {
            border: 1px solid #e6e6e6;
            border-top: none;
            padding: 10px 5px;
            overflow: auto;
            height: -webkit-calc(100vh - 125px);
            height: -moz-calc(100vh - 125px);
            height: calc(100vh - 125px);
        }

        .layui-tree-entry .layui-tree-txt {
            padding: 0 5px;
            border: 1px transparent solid;
            text-decoration: none !important;
        }

        .layui-tree-entry.ew-tree-click .layui-tree-txt {
            background-color: #fff3e0;
            border: 1px #FFE6B0 solid;
        }

        /* 右表搜索表单 */
        #organizationUserTbSearchForm .layui-form-label {
            box-sizing: border-box !important;
            width: 90px !important;
        }

        #organizationUserTbSearchForm .layui-input-block {
            margin-left: 90px !important;
        }

        #userTable + .layui-table-view .layui-table-body tbody > tr > td {
            padding: 0;
        }

        #userTable + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
            height: 48px;
            line-height: 48px;
        }

        .tb-img-circle {
            width: 40px;
            height: 40px;
            cursor: zoom-in;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }
    </style>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid" style="padding-bottom: 0;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 10px;">
                    <!-- 树工具栏 -->
                    <div class="layui-form toolbar" id="organizationTreeBar">
						区域分类
                    </div>
                    <!-- 左树 -->
                    <div id="organizationTree"></div>
                </div>
            </div>
        </div>
        <div class="layui-col-md9">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 10px;">
                    <!-- 数据表格 -->
					<table id="userTable" lay-filter="userTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="userTbBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="userTbState">
    <input type="checkbox" lay-filter="userTbStateCk" value="{{d.userId}}" lay-skin="switch"
           lay-text="正常|锁定" {{d.state==1?'checked':''}} style="display: none;"/>
    <p style="display: none;">{{d.state==1?'正常':'锁定'}}</p>
</script>
<script type="text/html" id="userTbSex">
    {{# if(d.sex==1){ }}
	<span style="cursor: default;">男</span>
	{{# }else if(d.sex==2){ }}
    <span style="cursor: default;">女</span>
    {{# } }}
</script>
<!-- 表格状态列 -->
<script type="text/html" id="eDialogTbState">
    {{# if(d.if_tyjz=="" || d.if_tyjz==null){ }}
	<span style="cursor: default;" class="text-muted">未申请</span>
	{{# }else if(d.if_tyjz==2){ }}
    <span style="color: orange;cursor: default;" lay-tips="请前往审核页面进行审核">待审核</span>
    {{# }else if(d.if_tyjz==0){ }}
	<span style="cursor: default;" class="text-danger">未通过</span>
    {{# }else if(d.if_tyjz==1){ }}
    <span class="icon-text" style="color: green;cursor: pointer;" lay-event="checkList">
        已通过<i class="layui-icon layui-icon-tips"></i>
    </span>
    {{# } }}
</script>
<script type="text/html" id="eDialogTbState2">
    {{# if(d.if_zdy=="" || d.if_zdy==null){ }}
	<span style="cursor: default;" class="text-muted">未申请</span>
	{{# }else if(d.if_zdy==2){ }}
    <span style="color: orange;cursor: default;" lay-tips="请前往审核页面进行审核">待审核</span>
    {{# }else if(d.if_zdy==0){ }}
	<span style="cursor: default;" class="text-danger">未通过</span>
    {{# }else if(d.if_zdy==1){ }}
    <span class="icon-text" style="color: green;cursor: pointer;" lay-event="checkList">
        已通过<i class="layui-icon layui-icon-tips"></i>
    </span>
    {{# } }}
</script>

<!-- js部分 -->
<script type="text/javascript" src="/Public/easyweb/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="/Public/easyweb/assets/js/common.js?v=318"></script>
<script type="text/javascript" src="/Public/easyweb/public.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'tree', 'dropdown', 'xmSelect', 'treeTable', 'zTree'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var tree = layui.tree;
        var xmSelect = layui.xmSelect;
        var selObj, treeData;  // 左树选中数据
		
		var r_postcode = null;

        /* 渲染树形 */
        function renderTree() {
            $.get('<?php echo U("Sys/role_list_left");?>', function (res) {
			//console.log(res.data);
                for (var i = 0; i < res.data.length; i++) {
                    res.data[i].title = res.data[i].organizationName;
                    res.data[i].id = res.data[i].organizationId;
					if( res.data[i].level <=2){
						res.data[i].spread = true;
					} 
                }
				
                treeData = layui.treeTable.pidToChildren(res.data, 'organizationId', 'parentId');
				//console.log(treeData);
                tree.render({
                    elem: '#organizationTree',
                    onlyIconControl: true,
                    data: treeData,
                    click: function (obj) {
                        selObj = obj;
                        $('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
                        $(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
                        insTb.reload({
                            where: {r_postcode: obj.data.r_postcode},
                            page: {curr: 1},
                            url: '<?php echo U("Userlistapp/user_list_right");?>'
                        });
                    }
                });
				//console.log(res);
				var dept_id = res.dept_id;
                $('#organizationTree').find('div[data-id="'+dept_id+'"]>.layui-tree-entry:first>.layui-tree-main>.layui-tree-txt').trigger('click');
            });
        }

        renderTree();
		
        /* 渲染表格 */
        var insTb = table.render({
            elem: '#userTable',
            data: [],
            height: 'full-52',
            page: true,
			toolbar: ['<p>',
                '</p>'].join(''),
            cellMinWidth: 100,
            cols: [[
				{type: 'checkbox'},
                {type: 'numbers'},
				{
                    title: '头像', templet: function (d) {
                        var url = d.imgUrl || 'http://obs.tqqmjs.cn/userlist/touxiang/默认头像.png';
                        return '<img data-index="' + (d.LAY_INDEX - 1) + '" src="' + url + '" class="tb-img-circle" tb-img alt=""/>';
                    }, align: 'center', width: 90, unresize: true
                },
                {field: 'nickname', title: '用户昵称', sort: true},
				{field: 'phone', title: '账号', sort: true, width: 120},
				{field: 'sex', title: '性别', templet: '#userTbSex', sort: true, width: 80},
				{toolbar: '#eDialogTbState', sort: true, title: '是否是体育记者', width: 150},
				{toolbar: '#eDialogTbState2', sort: true, title: '是否是社会指导员', width: 160},
				{field: 'zc_r_postcode', title: '当前区域', sort: true, width: 110},
                {
                    field: 'createTime', title: '创建时间', width: 160, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, sort: true
                },
                {field: 'state', title: '状态', templet: '#userTbState', sort: true, width: 100},
                {title: '操作', toolbar: '#userTbBar', align: 'center'}
            ]],
            done: function (res) {
               //console.log(res);
				r_postcode = res.r_postcode;

				if( typeof(r_postcode) == "undefined"){
					$('.p_btn_add').hide();
					$('.p_btn_delete').hide();
				}else{
					admin_perms(res,"<?php echo $_GET['id']; ?>"); //检测=》要展示哪些按钮 //参数：res + 当前页面主键id
				}
            }
        });
		
		/* 点击图片放大 */
        $(document).off('click.tbImg').on('click.tbImg', '[tb-img]', function () {
            var imgList = table.cache['userTable'].map(function (d) {
                return {
                    alt: d.nickName,
                    src: d.imgUrl || 'http://obs.tqqmjs.cn/userlist/touxiang/默认头像.png'
                }
            });
            layer.photos({photos: {data: imgList, start: $(this).data('index')}, shade: .1, closeBtn: true});
        });
		
		/* 表格工具条点击事件 */
        table.on('tool(userTable)', function (obj) {
            if (obj.event === 'del') { // 删除
			/*layer.msg('暂未开放此功能，若有需要 请联系超级管理员', {icon: 2});
            return;*/
                doDel(obj);
            } else if (obj.event == 'checkList') { //体育记者/社会指导员审核失败/通过原因展示
				//console.log(obj.data);
				//openCheckList(obj.data);//暂时用不到 若要用到 \page\example\dialog  里看
            }
        });
		
		/* 表格头工具栏点击事件 */
        
		
		/* 删除 */
        function doDel(obj) {
		//console.log(obj);
            layer.confirm('确定要删除选中数据吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                var loadIndex = layer.load(2);
				$.post('<?php echo U("Sys/p_Delete");?>', {id: obj.data ? obj.data.userId : obj.ids,type:'userlist'}, function (res) {
                    layer.close(loadIndex);
					//console.log(res);
                    if (res.code === 200 || res.code === "1") {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'json');
            });
        }
		
		/* 修改用户状态 */
        form.on('switch(userTbStateCk)', function (obj) {
		//console.log(obj);
           var loadIndex = layer.load(2);
			$.post('<?php echo U("Sys/role_state");?>', {
                userId: obj.elem.value,
                state: obj.elem.checked ? 1 : 0,
				type:'userlist'
            }, function (res) {
                layer.close(loadIndex);
                if (res.code === 200) {
                    layer.msg(res.msg, {icon: 1});
                } else {
                    layer.msg(res.msg, {icon: 2});
                    $(obj.elem).prop('checked', !obj.elem.checked);
                    form.render('checkbox');
                }
            }, 'json');
        });

    });
</script>
</body>
</html>